﻿using System.Collections.Generic;
using System.Data;
using eCommerce.core;
using eCommerce.core.Helpers;
using eCommerce.db.DALRespository;
using eCommerce.db.DataRespository;

namespace eCommerce.db.BORespository
{
    public class OrderBo
    {
        public static List<OrderEntity> Search(string keyword, int status, int storeId, int adminUserId,
                                               string startDate, string endDate, int pageIndex, int pageSize, ref int totalRecords)
        {
            return OrderDal.Search(keyword, status, storeId, adminUserId, startDate, endDate, pageIndex, pageSize, ref totalRecords);
        }

        public static DataTable GetByStatus(int status)
        {
            return OrderDal.GetByStatus(status);
        }

        public static DataTable GetByCustomerId(int customerId)
        {
            return OrderDal.GetByCustomerId(customerId);
        }

        public static DataTable GetListAdminUser(int storeId)
        {
            return OrderDal.GetListAdminUser(storeId);
        }

        public static DataTable GetListStore(int storeId)
        {
            return OrderDal.GetListStore(storeId);
        }

        public static int Create(OrderEntity o)
        {
            return OrderDal.Create(o);
        }

        public static void Delete(int id)
        {
            OrderDal.Delete(id);
        }

        public static void UpdateStatus(int id, int status)
        {
            OrderDal.UpdateStatus(id, status);
        }

        public static void UpdateNote(int id, string note)
        {
            OrderDal.UpdateNote(id, note);
        }

        public static OrderEntity GetById(int id)
        {
            return OrderDal.GetById(id);
        }

        public static int GetStatistic(int status)
        {
            return OrderDal.GetStatistic(status);
        }

        public static string GetTotalOrderAndMoneyByCustomer(int customerId)
        {
            var orders = OrderDal.GetTotalOrderByCustomerId(customerId, (int) OrderStatus.Complete);
            var money  = OrderDal.GetTotalMoneyByCustomerId(customerId, (int) OrderStatus.Complete);

            return orders > 0 && money > 0 ? string.Format("{0} hóa đơn | Tổng tiền: {1}", orders, Utils.FormatPrice(money)) : "-";
        }
    }
}
